﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Distribution.Service;
using Entities;

namespace DistributionApplication.Controls
{
    public partial class AssignNotes : UserControl
    {
        public AssignNotes()
        {
            InitializeComponent();
        }

        public void LoadCombos()
        {
            List<ELookUp> inspectionResults = LLookUpService.GetAll(LookUpType.InspectionResult);
            MobileUIHelper.FillListbox(lstParentNotes, inspectionResults.ToArray(), null);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (lstParentNotes.SelectedIndex >= 0)
            {
                lstChildNotes.Items.Add(lstParentNotes.SelectedItem);
                lstParentNotes.Items.Remove(lstParentNotes.SelectedItem);
            }
        }

        private void bntRemove_Click(object sender, EventArgs e)
        {
            if (lstChildNotes.SelectedIndex >= 0)
            {
                lstParentNotes.Items.Add(lstChildNotes.SelectedItem);
                lstChildNotes.Items.Remove(lstChildNotes.SelectedItem);
            }
        }

        public List<ELookUp> GetSelectedValues()
        {
            List<ELookUp> notes = new List<ELookUp>();

            foreach (ELookUp note in lstChildNotes.Items)
                notes.Add(note);

            return notes;             
        }

        public void SetSelectedValues(List<ELookUp> notes)
        {
            Reset();
            
            foreach (ELookUp note in notes) 
            {
                lstParentNotes.Items.Remove(note);
                lstChildNotes.Items.Add(note);
            }
        }

        public void Reset()
        {
            lstChildNotes.Items.Clear();
            LoadCombos();
        }
    }
}
